#ifndef __thread_pool_h_
#define __thread_pool_h_ 1
#include "sys.h"

enum{
    THREAD_POOL_AUTO_EXTERN = 0x1,
};

typedef void *(*thread_task_fun)(void *arg);
typedef struct _thread_task{
    struct _thread_task *next;
    thread_task_fun fun;
    void *arg;
}thread_task_t;

typedef struct {
    char label[32];
    int feature;
    int shutdown;
    int limit_number;
    int normal_number;
    int cur_task_number;
    int max_task_number;
    int running_number;
    int extern_number;
    thread_task_t *task_list;

    pthread_mutex_t mutex;
    pthread_cond_t cond, destroy_cond;
}thread_pool_t;

extern thread_pool_t* thread_pool_new(int normal_number);
extern void thread_pool_set_name(thread_pool_t* tp, char *label);
extern int thread_pool_add_task(thread_pool_t* tp, thread_task_fun fun, void* arg);
extern void thread_pool_destroy(thread_pool_t *tp);
extern int thread_pool_get_running_number(thread_pool_t *tp);
extern int thread_pool_get_task_number(thread_pool_t *tp);
extern void thread_pool_shutdown(thread_pool_t *tp);
extern int thread_pool_set_auto_extern(thread_pool_t *tp);
extern int thread_pool_set_limit_number(thread_pool_t* tp, int limit_number);
extern int thread_pool_set_max_task_number(thread_pool_t* tp, int max_task_number);
extern void thread_pool_wait(thread_pool_t *tpool);
#endif